library(estimatr) 
library(ggplot2)
library(dplyr)
library(dotwhisker)
library(gridExtra)
library(coefplot)
library(tidyverse)


# Figure 8: Minimum Likelihood of Success, by Nuclear Theory

setwd("/Users/dmin/Dropbox/Replication_Data/Paper_2/")

Dat <- read.csv("Paper_2_Data_Clean.csv", stringsAsFactors = FALSE)

gg_df <-
  Dat %>%
  group_by(Quadrant) %>%
  summarize(tidy(
    lm_robust(
      outcome_custom ~ 1,
      data = cur_data()
    )
  ))

theorylabels<-c("Low Harm\nLow Risk","Low Harm\nHigh Risk","High Harm\nLow Risk","High Harm\nHigh Risk" )

p<- ggplot(data=Dat, aes(x=as.factor(Quadrant), y=outcome_custom, fill = as.factor(Quadrant)), inherit_aes=FALSE) + 
  geom_jitter(width=.3, height=3, alpha=0.2)+
  geom_point(data=gg_df, aes(x=Quadrant, y=estimate, size=5, color=as.factor(Quadrant), stroke=0), inherit.aes = FALSE)+
  geom_errorbar(data=gg_df, aes(x=Quadrant, ymin=conf.low, ymax=conf.high, width = .5, color=as.factor(Quadrant), size=2), inherit.aes = FALSE) +
  scale_x_discrete(labels=theorylabels) + 
  scale_color_manual(values=c("1"="green3","2"="yellow3","3"="orange3", "4"="red3")) + 
  theme_bw() + xlab("Quadrant") + 
  ylab("Minimum Likelihood of Success to Approve Nuclear Use") + 
  theme(legend.position="none")

g <- p + annotate("rect", xmin=-.2, xmax = 5, ymin=105, ymax = 114, alpha=.2, fill="blue" ) + annotate("text", x=0.2, y=110, label="Never") +
  coord_cartesian(ylim=c(-10,110))
g

ggsave("Image_10.png", plot=g, width=2500, height=2500, units=c("px"))



